package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.AdNewsAuthDto;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/api/v1/news")
public class NewsController {

    @Resource
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findAll(dto);
    }

    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submitNews(dto);
    }

    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    @PostMapping("/list_vo")
    public ResponseResult findNews(@RequestBody @Valid AdNewsAuthDto dto) {
        return wmNewsService.findNews(dto);
    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult details(@PathVariable("id") Integer id) {
        return wmNewsService.WmNewsDetails(id);
    }

    @PostMapping("/auth_fail")
    public ResponseResult auth_fail(@RequestBody AdNewsAuthDto dto){

        //更新WmNews为审核失败
        return wmNewsService.auth_fail(dto);
    }

    @PostMapping("/auth_pass")
    public ResponseResult auth_pass(@RequestBody AdNewsAuthDto dto){
        //更新WmNews为审核通过
        return wmNewsService.auth_pass(dto);
    }
}
